package cn.tedu.homeworkivos.user.service.impl;

import cn.tedu.homeworkivos.base.exception.ServiceException;
import cn.tedu.homeworkivos.base.response.StatusCode;
import cn.tedu.homeworkivos.user.mapper.UserMapper;
import cn.tedu.homeworkivos.user.pojo.dto.LoginParam;
import cn.tedu.homeworkivos.user.pojo.vo.UserLoginVO;
import cn.tedu.homeworkivos.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public UserLoginVO login(LoginParam param) {
        log.debug("用户登录，参数={}",param);
        UserLoginVO uvo=userMapper.selectByUsername(param.getUsername());
        if(uvo==null)
        {
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if(!uvo.getPassword().equals(param.getPassword()))
        {
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        return uvo;
    }
}
